const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({
  data: {
    type:'',
    isselect:false,
    categoryId:'',
 
    page:1,
    pageSize:10,
    categoryList:[],
    accessList:[]
  },
  onLoad(option) {
    this.getCategoryList()
    this.getAccessListByLawyer()
  },
  onShow(){
   
  },
  select(){
    this.setData({
      isselect:!this.data.isselect
    })
  },
  selectoption(e){
    this.setData({
      isselect:false,
      type:e.currentTarget.dataset.name,
      categoryId:e.currentTarget.dataset.id
    })
  },
  //搜索
  search(){


    this.setData({
     accessList:[],
     page:1,
     isEnd:false
    },()=>{
      this.getAccessListByLawyer()
    })
  },
  accept(){
    wx.showModal({
        title: '',
        content: "确定接单吗？",
        confirmColor:'#0557A8',
        cancelColor:'#C2C2C2',
        success (res) {
          if (res.confirm) {
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
  },
  
  golink(e){
    var url=e.currentTarget.dataset.url+'?id='+e.currentTarget.dataset.id;
    // if (!wx.getStorageSync('logintoken')) {
    //   app.goLogin(false)
    //   return
    // }
    wx.navigateTo({
      url
    });
  },
   //获取类型列表
   getCategoryList(){
    Controller.categoryList({}).then(res=>{
      let baseData=res.data.baseData

    
      
      this.setData({
        categoryList:baseData
      })
    })
    },

  // 获取我的案源列表
   getAccessListByLawyer(){
     let categoryId= this.data.categoryId
     let page=this.data.page
     let pageSize=this.data.pageSize
    Controller.accessListByLawyer({categoryId,page,pageSize}).then(res=>{
       let baseData=res.data.baseData
       

       baseData.list.map((item,index)=>{
        
        
        if(item.categoryTitle){
          item.categoryTitle=item.categoryTitle.split(',')
        }else{
          item.categoryTitle=[]
        }

     
      
          
           this.data.accessList.push(item)
       })

       this.setData({
        accessList:this.data.accessList,
        isEnd:baseData.lastPage
       })
    })
   },
  onShareAppMessage: function (e) {
    
  },
  onShareTimeline: function(res){
    
  },
  onReachBottom:function(){
    if(this.data.isEnd){
      return
    }else{
      this.data.page=this.data.page+1
      this.getAccessListByLawyer()
    }
  }

})